<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('标签列表')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="tag-form">
					<div class="select-list">
						<ul>
							<li>
								<label>标签名：</label>
								<input type="text" name="tagName" />
							</li>
							<li>
								<label>标签状态：</label>
								<select name="visible" th:with="type=${@dict.getType('cms_tag_visible')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label>标签类型：</label>
								<select name="tagType" th:with="type=${@dict.getType('cms_support_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
										th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li class="select-time">
								<label>创建时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间"
									name="params[beginTime]" />
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间"
									name="params[endTime]" />
							</li>
							<li>标签所属：<select  name="params[supportType]">
									<option value="">所有</option>
									<option th:each="themeName: ${themeNames}" th:text="${themeName}"
										th:value="${themeName}">
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
										class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
										class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<div class="btn-group" shiro:hasPermission="cms:tag:edit">
					<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">状态设置 <span
							class="caret"></span>
					</button>
					<ul class="dropdown-menu" id="tagVisible" th:with="type=${@dict.getType('cms_tag_visible')}">
						<li th:each="dict : ${type}" th:data-id="${dict.dictValue}"><a href="javascript:void(0)"
								th:text="${dict.dictLabel}"></a></li>
					</ul>
				</div>
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="cms:tag:add">
					<i class="fa fa-plus"></i> 新增
				</a>
				<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
					shiro:hasPermission="cms:tag:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
					shiro:hasPermission="cms:tag:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
			</div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('cms:tag:edit') }]];
		var removeFlag = [[${@permission.hasPermi('cms:tag:remove') }]];
		var tagVisibles = [[${@dict.getType('cms_tag_visible') }]], tagTypes = [[${@dict.getType('cms_support_type') }]];
		var prefix = ctx + "cms/tag";
		$(function () {
			var options = {
				url: prefix + "/list",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				sortName: "tagName",
				modalName: "内容标签",
				columns: [{
					checkbox: true
				},
				{
					field: 'tagId',
					title: '标签编号'
				},
				{
					field: 'tagName',
					title: '标签名称',

				},
				{
					field: 'perms',
					title: '权限字符',
					visible: false
				},
				{
					field: 'tagUrl',
					title: '标签地址',
					visible: false

				},
				{
					field: 'tagIco',
					title: '标签图标',
					visible: false
				},
				{
					field: 'keywords',
					title: '关键词',
					align: "left",
					visible: false
				},
				{
					field: 'description',
					title: '描述',
					align: "left",
					visible: false
				},
				{
					field: 'visible',
					title: '标签状态',
					align: 'center',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(tagVisibles, value);
					}
				}
					,
				{
					field: 'tagType',
					title: '标签类型',
					align: 'center',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(tagTypes, value);
					}
				},
				{
					field: 'tagCount',
					title: '关联文章',
				},
				{
					field: 'createBy',
					title: '创建人ID',
					sortable: true
				},
				{
					field: 'createTime',
					title: '创建时间',
					sortable: true
				},
				{
					field: 'updateBy',
					title: '更新人ID',
					sortable: true,
					visible: false
				},
				{
					field: 'updateTime',
					title: '更新时间',
					sortable: true,
					visible: false
				},
				{
					title: '操作',
					align: 'center',
					formatter: function (value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tagId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="relation(\'' + row.tagId + '\')"><i class="fa fa-eye"></i>查看关联</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tagId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
					}
				}]
			};
			$.table.init(options);
		});

		/*文章顶置下拉框点击事件*/
		$('#tagVisible>li').click(function (e) {
			//获取选中行数据
			var pam = {}, tagIds = [], chooseData = $("#bootstrap-table").bootstrapTable('getSelections');
			pam.visible = $(this).attr("data-id");
			if (chooseData.length > 0) {
				$.each(chooseData, function (index, ele) {
					tagIds.push(ele.tagId);
				});
				pam.tagIds = tagIds.join();

				$.modal.confirm("确认要修改选的标签状态吗？", function () {
					$.operate.post(prefix + "/editTagVisible", pam);
				})
			}
			else {
				$.modal.alert("请至少选择一项");

			}
		});
		function relation(tagId) {
			$.modal.open("查看关联文章", prefix + "/relation/" + tagId);
		}
	</script>
</body>

</html>
